home *** CD-ROM | disk | FTP | other *** search
- -- 2001.01.27
- -- Clive Green <clivegreen@atlas.co.uk>
-
- ------------------------------------------------------------------------------------------------------
-
- -- establishes conditions; updates data settings accordingly.
-
- ------------------------------------------------------------------------------------------------------
-
- -- declare properties:
- property main -- main code directory object
- property dataManager -- the data management and storage object
- property elements -- a list of known conditions and their criteria
- property groups -- a list of condition groupings with boolean flags
- property outcomes -- a list of outcomes with condition criteria
-
- property conditionStates -- a list of actual condition states obtained
- property groupStates -- a list of condition groups and their status
-
- ------------------------------------------------------------------------------------------------------
-
- on new me,L
-
- -- (1) extract and check arguments:
-
- -- check for a parameter list:
- if ilk(L) <> #propList then return ¬
- [#error:#noParamListSupplied, #msg:"conditionsService:new"]
-
- -- a reference to the parent codebase is REQUIRED:
- main = L[#main]
- if (ilk(main) <> #instance) then return ¬
- [#error:#noMainObjectSupplied, #msg:"conditionsService:new"]
-
- --------------------
-
- -- (2) obtain required data:
- dataManager = main.getDataManager()
-
- elements = dataManager.getData([#set:#conditionElements])
- groups = dataManager.getData([#set:#conditionGroups])
- outcomes = dataManager.getData([#set:#outcomes])
-
- --------------------
-
- -- (3) what is the status of each known condition element?
- conditionStates = me.getConditionStates()
-
- --------------------
-
- -- (4) which groups of conditions actually exist?
-
- -- create a list to hold the status of each group:
- groupStates = [:]
-
- -- examine the specified conditions for each group in turn:
- repeat with i = 1 to count(groups)
-
- -- get the name and conditions listing for group i:
- g = getPropAt(groups,i)
- cL = getAt(groups,i)
-
- -- for a group to be valid, ALL of the condition states it specifies
- -- must be matched:
-
- -- set a boolean flag, and then test each condition listed within group g:
- f = 1
- repeat with j = 1 to count(cL)
-
- -- what is the name and specified state of the jth listed condition?
- cn = getPropAt(cL,j)
- v = getAt(cL,j)
-
- -- what is the actual state of condition cn?
- status = conditionStates[cn]
-
- -- IMPORTANT ASSUMPTION:
- -- assume that unidentifed conditions have NOT been met!!!
- if voidP(status) then status = 0
-
- -- does the required state for condition cn match its actual state?
- if status = v then next repeat
-
- -- they didn't match - group g is out of luck:
- f = 0
- exit repeat
-
- end repeat
-
- -- store the validity or otherwise of group g:
- groupStates[g] = f
-
- end repeat
-
- --------------------
-
- -- pass back my address:
- return me
-
- ----------------------------------------------------------------------------------------------------
-
- on getConditionStates me
-
- -- establish the status of all specified conditions:
- cL = [:]
- repeat with i = 1 to count(elements)
-
- -- obtain the ith condition name and criteria listing:
- cn = getPropAt(elements,i)
- cd = getAt(elements,i)
-
- -- store the determined state of the condition cn:
- cL[cn] = me.getConditionState(cd)
-
- end repeat
-
- -- pass compiled listing back to caller:
- return cL
-
- ----------------------------------------------------------------------------------------------------
-
- on getConditionState me,cd
-
- -- just one of the criterion listed within cd can be met in order for the condition as a whole
- -- to be fulfilled:
-
- -- examine each criterion in the listing (cd) supplied:
- repeat with i = 1 to count(cd)
-
- -- extract the ith criterion's name and value:
- xn = getPropAt(cd,i)
- xd = getAt(cd,i)
-
- -- process the criterion xn according to its name:
- case xn of
-
- #winRegKey:
-
- -- stop when first successful registry entry is obtained:
- if me.winRegKeyTest(xd) then return 1
-
- #platformTest:
-
- -- what is the current host?
- um = main.getUtilityMethods()
- p = um.thePlatform()
-
- -- does the current platform symbol match the one specified by xd?
- if (p = xd) then return 1
-
- #osTest:
-
- -- obtain the operating system name:
- xm = main.getXtrasManager()
- buddy = xm.getBuddyAPIxtra()
- os = buddy.getOSName()
-
- -- Windows 2000 returns "Win2000";
- -- Windows NT4 returns "WinNT";
- -- Windows 98 and Windows ME each return "Win98"
- -- Windows 95 returns "Win95"
-
- -- does the current operating system name commence with the string xd?
- if (os starts xd) then return 1
-
- end case
-
- end repeat
-
- -- we reach this point when any none of the above criteria succeed:
- return 0
-
- ----------------------------------------------------------------------------------------------------
-
- on winRegKeyTest me,xd
-
- -- we need to check the windows registry for an entry which fulfils the requirements listed in xd:
-
- -- for this we can use the buddyAPIxtra:
- xm = main.getXtrasManager()
- buddy = xm.getBuddyAPIxtra()
-
- --------------------
-
- -- extract the windows registry criteria listed within xd:
-
- -- which branch of the registry is to be looked in?
- b = xd[#branch]
-
- -- what key location should we examine?
- k = xd[#key]
-
- -- any particular value name in particular?
- n = xd[#name]
-
- -- what would constitute a matching valueName?
- nm = xd[#nameMatch]
-
- -- any particular value required for n?
- v = xd[#value]
-
- -- and how precise do we need to be when matching the value v with what's in the registry?
- vm = xd[#valueMatch]
-
- --------------------
-
- -- first, determine whether the specified registry branch & key exist:
- L = buddy.getRegistryValueNames([#branch:b, #keyName:k])
- if L = [] then return 0
-
- --------------------
-
- -- was any value name provided for further investigation?
- -- if not, then we're done ...
- if voidP(n) then return 1
-
- -- ie: confirming the key's existence was all that was needed
-
- --------------------
-
- -- was an exact match located?
- nf = getPos(L,n)
-
- -- and was a valueName match criteria (nm) specified?
- if voidP(nm) then return nf
-
- -- ie: the exact specified value name either was or wasn't found, and that was enough
-
- --------------------
-
- -- nm affects how fussy we should be in trying to 'find' the value name n:
- case nm of
-
- #exact:
-
- -- we need to find a precise match within L in order to continue:
- if not nf then return 0
-
- #startsWith:
-
- -- recurse over the list L looking for value names beginning with n:
- matchFlag = 0
- repeat with i in L
-
- if i starts n then
-
- -- we found a 'match'!
- matchFlag = 1
- exit repeat
-
- end if
-
- end repeat
-
- -- fail if we didn't get a value name starting with n:
- if not matchFlag then return 0
-
- -- we found a 'match' with the ith inspected value name -
- -- let's modify our value of n accordingly before continuing:
- n = i
-
- end case
-
- --------------------
-
- -- what value (if any) does the value n need to have?
-
- -- if none is specified, our tests are complete:
- if voidP(v) then return 1
-
- --------------------
-
- -- a value (v) is specified - what one have we got in the registry?
- s = buddy.getRegistryString([#branch:b, #keyName:k, #valueName:n])
-
- -- do we have any information about what constitutes a matching value?
- if voidP(vm) then
-
- -- no value match criteria was provided, so just look for an exact match,
- -- and return the result:
- return (s = v)
-
- else
-
- -- a match criteria was specified - check it out:
- case vm of
-
- #any:
-
- -- that's it - we're sorted:
- return 1
-
- #startsWith:
-
- -- the value we found in the registry only has to begin with the string that
- -- is specified by v:
- return (s starts v)
-
- otherwise
-
- -- I don't know how to deal with any other match criteria -
- -- assume failure:
- return 0
-
- end case
-
- end if
-
- --------------------
-
- -- we never get here:
- return 1
-
- ----------------------------------------------------------------------------------------------------
-
- on testCondition me,c
-
- -- provide caller with the last known status of the condition called c:
- s = conditionStates[c]
-
- -- unknown conditions produce a zero:
- if voidP(s) then s = 0
-
- return s
-
- ----------------------------------------------------------------------------------------------------
-
- on evalOutcome me,L
-
- -- (1) extract and check arguments:
-
- -- check for a parameter list:
- if ilk(L) <> #propList then return ¬
- [#error:#noParamListSupplied, #msg:"conditionsService:evalOutcome"]
-
- -- an outcome ID is needed:
- id = L[#outcomeID]
- if not symbolP(id) then return ¬
- [#error:#noOutcomeIDSupplied, #msg:"conditionsService:evalOutcome"]
-
- -- the id must be known to us:
- gL = outcomes[id]
-
- if ilk(gL) <> #propList then return ¬
- [#error:#unknownOutcomeID, #msg:"conditionsService:evalOutcome: ID =" && id]
-
- --------------------
-
- -- test for the status of each condition group belonging to the outcome known as (id):
- repeat with i = 1 to count(gL)
-
- -- pull ith groupName and glueID:
- groupID = getPropAt(gL,i)
- glueID = getAt(gL,i)
-
- -- is this a valid group?
- s = groupStates[groupID]
-
- -- unrecognised groups are considered invalid:
- if voidP(s) then s = 0
-
- -- skip invalid groups:
- if not s then next repeat
-
- -- if we get here, then we've found a valid condition group -
- -- the outcome is a glue call to application code...
- return glue(glueID)
-
- end repeat
-
- -- if we got here, there was no valid outcome for the outcomeID supplied to us (oops):
- return ¬
- [#error:#unevaluatedOutcome, #msg:"conditionsService:evalOutcome: ID =" && id]
-
- ----------------------------------------------------------------------------------------------------